<?php
namespace Roomer\Controller;
use Think\Controller;
class ProductionController extends Controller
{
    public function index()
    {
        $this->checkSession();
        $this->recordList();
        $this->display();
    }

    public function order()
    {
        $this->checkSession();
        $this->display();
    }

    public function recordList()
    {
        $this->checkSession();
        $record = M('production');
        $total = $record->count();
        $per =15;
        import('Org.Util.Page');
        $page = new \Page($total, $per);
        $sql = "select * from hotel_production " . $page->limit;
        $query = $record->query($sql);
        $pageList = $page->fpage();
        $this->assign('param', $query);
        $this->assign('pageList', $pageList);
        $this->assign('num', 1);
    }

    public function  edit_production()
    {
        $this->checkSession();
        $this->editDisplay();
        $this->display();
    }

    public function editDisplay()
    {
        $this->checkSession();
        $production_id = $_GET['production_id'];
        $info = M('production')->where("production_id=$production_id")->find();
        //$this->assign('admin',$admin);
        $this->assign('info', $info);

    }
    public function edit_productions(){
        $this->checkSession();
        $production = M('production');
        $data['production_id']=$_POST['production_id'];
        $data['production_name'] = $_POST['production_name'];
        $data['production_price'] = $_POST['production_price'];
        $data['production_number']=$_POST['production_number'];

        if ($production->save($data)) {
            $this->success('更新数据成功', U('production/index'));
        } else {
            $this->error('发生未知错误或者未进行数据更新，请重试');
        }
        /*    }else{
                $this->error('该身份证已经被注册，请重试');

            }*/

    }
    public function check_orders(){
        $this->checkSession();
        $record = M('production_order');
        $total = $record->count();
        $per = 15;
        import('Org.Util.Page');
        $page = new \Page($total, $per);
        $sql = "select * from hotel_production_order " . $page->limit;
        $query = $record->query($sql);
        $pageList = $page->fpage();
        $this->assign('param', $query);
        $this->assign('pageList', $pageList);
        $this->assign('num', 1);
        $this->display();
    }
    public function checkSession(){
        $roomer_id = $_SESSION['roomer_id'];
        if(isset($roomer_id)){
            $this->assign('roomer_id',$roomer_id);
        }else{
            $this->error("需先登录,方可进行查询！",U('Login/index'));
        }
    }
}